package com.mfin.persistence;

import org.hibernate.HibernateException;
import org.hibernate.StaleObjectStateException;

public class HibernateExceptionManager implements IPersistenceExceptionManager {
	public void handle(Throwable t) throws PersistenceException {
		if (t instanceof HibernateException) {
			if (t instanceof StaleObjectStateException) {
				StaleObjectStateException sose = (StaleObjectStateException) t;
				OptimisticLockingException ole = new OptimisticLockingException(
						new ObjectIdentity(sose.getIdentifier(),
								sose.getEntityName()));
				ole.setCause(t);
				throw ole;
			}
		}
		PersistenceException pe = new PersistenceException(t.getMessage());
		pe.setCause(t);
		throw pe;
	}
}
